import numpy
class IMS():
    def __init__(self):
        self.m:numpy.array=0
        self.s:numpy.array=0
        self.b:int=0
    def __call__(self,x:numpy.array)-> numpy.array:
        if self.b==0:
            self.b=1
            self.m=x
            self.s=numpy.zeros(x.shape)
            return x
        if x.shape !=self.m.shape:
            return x
        self.b=self.b+1
        self.m=self.m+1/self.b*(x-self.m)
        self.s=(self.b-1)/self.b*self.s+(self.b-1)/(self.b**2)*((x-self.m)**2)
        x = (x-self.m)/numpy.sqrt(self.s)
        x=x.astype(numpy.float32)
        return x